package com.hy.mydesktop.client.component.factory;

import com.extjs.gxt.charts.client.model.Legend;
import com.extjs.gxt.charts.client.model.Legend.Position;
import com.hy.mydesktop.client.component.meta.LegendModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;

/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-9-7；时间：下午01:42:16</li>
 * <li>类型名称：LegendFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class LegendFactory {
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建图例控件</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-9-7；时间：下午下午01:43:59</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	public static Legend createLegend(GxtComponentMetaNodeModel gxtComponentMetaNodeModel)
	{
		return configureLegend(gxtComponentMetaNodeModel);
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：配置图例的属性</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-9-7；时间：下午下午01:45:49</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static Legend configureLegend(GxtComponentMetaNodeModel gxtComponentMetaNodeModel)
	{
		Legend lg=defaultCreateLegend();
		//设置图例的透明度
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.ALPHA.name().toLowerCase())!=null)
		{
			float alpha=(Float)gxtComponentMetaNodeModel.get(LegendModelEnum.ALPHA.name().toLowerCase());
			lg.setAlpha(alpha);
		}
		//设置背景颜色
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.BACKGROUNDCOLOUR1.name().toLowerCase())!=null)
		{
			String backgroundColour=(String)gxtComponentMetaNodeModel.get(LegendModelEnum.BACKGROUNDCOLOUR1.name().toLowerCase());
			lg.setBackgroundColour(backgroundColour);
		}
		//设置边框
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.BORDER1.name().toLowerCase())!=null)
		{
			boolean border=(Boolean)gxtComponentMetaNodeModel.get(LegendModelEnum.BORDER1.name().toLowerCase());
			lg.setBorder(border);
		}
		// 边框颜色
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.BORDERCOLOUR.name().toLowerCase())!=null)
		{
			String borderColour=(String)gxtComponentMetaNodeModel.get(LegendModelEnum.BORDERCOLOUR.name().toLowerCase());
			lg.setBorderColour(borderColour);
		}
		//边界
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.MARGIN.name().toLowerCase())!=null)
		{
			Integer margin=(Integer)gxtComponentMetaNodeModel.get(LegendModelEnum.MARGIN.name().toLowerCase());
			lg.setMargin(margin);
		}
		//间距
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.PADDING.name().toLowerCase())!=null)
		{
			Integer padding=(Integer)gxtComponentMetaNodeModel.get(LegendModelEnum.PADDING.name().toLowerCase());
			lg.setPadding(padding);
		}
		//位置
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.POSITION.name().toLowerCase())!=null)
		{
			Position pos=(Position)gxtComponentMetaNodeModel.get(LegendModelEnum.POSITION.name().toLowerCase());
			lg.setPosition(pos);
		}
		//阴影
		if(gxtComponentMetaNodeModel.get(LegendModelEnum.SHADOW.name().toLowerCase())!=null)
		{
			boolean shadow=(Boolean)gxtComponentMetaNodeModel.get(LegendModelEnum.SHADOW.name().toLowerCase());
			lg.setShadow(shadow);
		}
		return lg;
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建默认的图例控件</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-9-7；时间：下午下午01:47:40</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @return
	 */
	private static Legend defaultCreateLegend()
	{
		Legend legend=new Legend(Position.RIGHT,true);
		legend.setPadding(10);
		return legend;
	}
}
